/*-----------------------------------------------------------------------*/
/* RAM disk control module for Win32              (C)ChaN, 2014          */
/*-----------------------------------------------------------------------*/

#include "diskio.h"
#include "ff.h"
#include "SDCard.h"
#include "stm32f10x.h"
#define SD_Card 0
extern SDCard Card;
extern USART cout;
/*--------------------------------------------------------------------------

   Module Private Functions

---------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------

   Public Functions

---------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive                                                 */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (
    BYTE pdrv		/* Physical drive nmuber */
)
{
	uint8_t res;
	switch(pdrv)
	{
		case SD_Card:
//			res = Card.Init();
//			cout.Printf("SD_Card Type:%s\r\n",Card.StatusToString[res]);
//    if((res==SDType::V2)||(res==SDType::V2HC))
				return RES_OK;
//			else
//				return RES_ERROR;
	}
	return RES_PARERR;
}



/*-----------------------------------------------------------------------*/
/* Get Disk Status                                                       */
/*-----------------------------------------------------------------------*/

DSTATUS disk_status (
    BYTE pdrv		/* Physical drive nmuber (0) */
)
{
	return RES_OK;
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s)                                                        */
/*-----------------------------------------------------------------------*/

DRESULT disk_read (
    BYTE pdrv,			/* Physical drive nmuber (0) */
    BYTE *buff,			/* Pointer to the data buffer to store read data */
    DWORD sector,		/* Start sector number (LBA) */
    UINT count			/* Number of sectors to read */
)
{
	switch(pdrv)
	{
		case SD_Card:
			while(count--)
			{
				Card.ReadBlock(sector,buff);
				buff+=512;
			}
			break;
	}
	return RES_OK;
}



/*-----------------------------------------------------------------------*/
/* Write Sector(s)                                                       */
/*-----------------------------------------------------------------------*/

DRESULT disk_write (
    BYTE pdrv,			/* Physical drive nmuber (0) */
    const BYTE *buff,	/* Pointer to the data to be written */
    DWORD sector,		/* Start sector number (LBA) */
    UINT count			/* Number of sectors to write */
)
{
	switch(pdrv)
	{
		case SD_Card:
			while(count--)
			{
				Card.WriteBlock(sector,(uint8_t*)buff);
				buff+=512;
			}
			break;
	}
	return RES_OK;
}



/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions                                               */
/*-----------------------------------------------------------------------*/

DRESULT disk_ioctl (
    BYTE pdrv,		/* Physical drive nmuber (0) */
    BYTE ctrl,		/* Control code */
    void* buff		/* Buffer to send/receive data block */
)
{
	return RES_OK;
}


